<?php


class Post_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		$this->load->database();//加载数据库
	}

	public function lists($num = FALSE, $offset = FALSE,$where=null)
	{
		$this->db->select('post.id,post.title,post.pv,post.images,post.keyword,post.description,post.create_time,category.title as category_title')->order_by("post.id", 'DESC');
		$this->db->join('category', 'category.id = post.category_id','left');
		$query=$this->db->get_where('post',$where,$num, $offset);
		return $query->result_array();
	}

	public function info($id)
	{
		return $this->db->select('post.*,post_content.content')->join('post_content', 'post_content.post_id = post.id','left')->get_where('post',array('post.id'=>$id))->row_array();
	}

	public function insert($data)
	{
		$this->db->insert('post',$data);
		return $this->db->insert_id(); //返回新插入的ID
	}

	public function update($id,$data)
	{
		return $this->db->where('id',$id)->update('post',$data);
	}

	/**
	 * 删除
	 */
	public function del($id)
	{
		return $this->db->delete('Post',array('id'=>$id));
	}
}
